let baseUrl = 'http://locahost:8083/Runing'


import store from '../store/index.js'
let methods = {
	get(url,params) {
		uni.showLoading({
			title:'加载中...'
		})
		return new Promise((resolve,reject) => {
			uni.request({
				url: baseUrl + url,
				method: "GET",
				data: params,
				success: (res) => {
					console.log(res)
					if (res.data.code != 200) {
						uni.hideLoading()
						uni.showToast({
							title: res.data.data.err,
							icon: 'none',
							duration:1000
						})
					}
					uni.hideLoading()
					resolve(res)
				},
				fail: (err) => {
					uni.hideLoading()
					reject(err)
				}
			})
		})
	},
	post(url,params) {
		uni.showLoading({
			title:'加载中...'
		})
		return new Promise((resolve,reject) => {
			uni.request({
				url: baseUrl + url,
				method: 'POST',
				data: params,
				success: (res) => {
					if (res.data.code != 200) {
						uni.hideLoading();
						uni.showToast({
							title: res.data.data.err,
							icon: 'none'
						})
					}
					uni.hideLoading();
					resolve(res)
				},
				fail: (err) => {
					console.log(err)
					uni.hideLoading();
					reject(err)
				}
			})
		})
	},
	put(url,params) {
		return new Promise((resolve,reject) => {
			uni.request({
				url: baseUrl + url,
				method: 'PUT',
				data: params,
				success: (res) => {
					if (res.data.code != 200) {
						uni.showToast({
							title: res.data.extend.err,
							icon: 'none'
						})
					}
					resolve(res)
				},
				fail: (err) => {
					reject(err)
				}
			})
		})
	}
}

export default methods